class p1 extends eui.Component{
	private zz:eui.Image;
	public j1:eui.Label;
    public j2:eui.Label;
public j3:eui.Label;
public j4:eui.Label;
public j5:eui.Label;
public j6:eui.Label;
public j7:eui.Label;
public j8:eui.Label;
public t1:eui.Label;
public t2:eui.Label;
private g1:eui.Group;
private scr1:eui.Scroller;
public jinbi:eui.Image;
public guan:eui.Image;
public guan2:eui.Image;
public guan3:eui.Image;


private g2:eui.Group;
private g3:eui.Group;
private g4:eui.Group;
private g5:eui.Group;
public g6:eui.Group;
public g7:eui.Group;
public erweima:eui.Image;
private num:number=0;
public guize:eui.Label;
public tixian:eui.Image;
private fail:any;
public yiti:eui.Label;
public leiji:eui.Label;
private jine:number=1;
public huode:eui.Label;
private time:number=0;
public g8:eui.Group;
public guan5:eui.Image;
public scr:eui.Scroller;
public gifts:any;
public jubao:eui.Image;
public qianbao:eui.Image;
public tixian2:eui.Image;
public fenxiang:eui.Image;
public g10:eui.Group;
public zailai:eui.Image;
public g9:eui.Group;
public xuanyao:eui.Image;
public g11:eui.Group;
public tixian3:eui.Image;
public chongzhi:eui.Image;
public g12:eui.Group;
public g13:eui.Group;
public num1:number=1;
public g14:eui.Group;
public huode3:eui.Label;
public g15:eui.Group;
public tijiao:eui.Image;
public xingming:eui.EditableText;
public shouji:eui.EditableText;
public dizhi:eui.EditableText;

private num2:number=1;
public t3:eui.Label;
public t4:eui.Label;
public t5:eui.Label;

public huode2:eui.Label;

public yu:eui.Label;

public yitixian:eui.Label;
public zuanyu:eui.Label;
public yiyong:eui.Label;











//400,340  432,418  400,500  320,526  240,496  210,416  252,336  330,308
	public constructor() {
		super();
		this.skinName="resource/skins/s1.exml"
		this.hehe();
	}
	private hehe():void{
		this.scr.scrollPolicyH="off"
		this.onlist()
		this.onloadUserInfo();
		this.jiangjin()
		//this.followdWind();
        
		this.g9.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g9.visible=false;
		},this);
		this.g10.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g10.visible=false;
		},this);
		this.guan.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g11.visible=false;
		},this);
		this.g12.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g12.visible=false;
		},this);
		this.g13.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g13.visible=false;
		},this);
		this.g14.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g14.visible=false;
			this.g15.visible=true;
		},this);
		this.tijiao.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			var mobile =this.shouji.text;  
          var re = /^1[3|5|7|8][0-9]\d{8}$/;  
           if(!re.test(mobile))  
           {  
               alert("手机号不合法");  
               return false;  
           }else if(this.xingming.text==""){
                alert("姓名不能为空")
		   }else if(this.dizhi.text==""){
                alert("地址不能为空")
		   }else if(this.shouji.text==""){
                alert("手机号不能为空")
		   }else{
			   this.ontijiao();
		   }
		   
		},this);
	
		this.guan2.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g4.visible=false;
		},this);
		this.guan3.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g5.visible=false;
		},this);
		this.guan5.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g8.visible=false;
		},this);
		this.jinbi.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.onjilu();
			this.g2.visible=true;
		},this);
		this.qianbao.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g11.visible=true;
		},this);
		
		this.fenxiang.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g13.visible=true;
		},this);
		this.xuanyao.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.g13.visible=true;
		},this);
		this.jubao.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			this.onjubao();
		},this);
		//this.chongzhi.addEventListener(egret.TouchEvent.TOUCH_TAP,(e:egret.TouchEvent)=>{
			//this.onchongzhi();
		//},this);

		this.tixian2.addEventListener(egret.TouchEvent.TOUCH_TAP,this.dianji,this)
		this.tixian3.addEventListener(egret.TouchEvent.TOUCH_TAP,this.dianji2,this)
		this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);

		this.addEventListener(egret.Event.ENTER_FRAME,(e:egret.Event)=>{
            this.scr1.viewport.scrollV +=1;
			if ((this.scr1.viewport.scrollV + this.scr1.height) >= this.scr1.viewport.contentHeight) {
                this.scr1.viewport.scrollV =0;
            }
		},this);
	}
	private dianji(e:egret.TouchEvent):void{
		if(this.yu.text=="0"){
			alert("您的余额为0")
		}else{
		this.tixian2.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.dianji,this)
		this.ontixian();
	    }
	}
	private dianji2(e:egret.TouchEvent):void{
		if(this.yu.text=="0"){
			alert("您的余额为0")
		}else{
		this.tixian3.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.dianji2,this)
		this.g11.visible=true;
		this.ontixian2();
	    }
	}
	private onjubao():void{
		window.location.href="http://ljla.wenmall.cn/wechat/jubao";
	}
	private ontijiao():void{
		var url =  "http://ljla.wenmall.cn/zp/uploadInfo?name="+this.xingming.text+"&tel="+this.shouji.text+"&address="+this.dizhi.text;

        
        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         

		 console.log(e.target.data);
		
           var jsObj = JSON.parse(e.target.data);
		   if(jsObj.rs==1){
                  alert("提交成功")
				  this.g15.visible=false;
}else{

		alert("提交失败");
}

        }, this);
        urlloader.load(req);
	}
	
	private onchongzhi():void{
		window.location.href="http://ljla.wenmall.cn/chb/pay?money=0.99&url=http://ljla.wenmall.cn/zhuan";
	}
	private s1():void{
		this.scr.viewport.scrollV=0;
		this.scr.scrollPolicyV="off"
		

				this.time-=1;
				this.t1.text=this.time+""
		
       
        this.zz.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
		this.addEventListener(egret.Event.ENTER_FRAME,this.yi,this);
		var timer:egret.Timer=new egret.Timer(2000,1);
		timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE,(e:egret.TimerEvent)=>{
            this.removeEventListener(egret.Event.ENTER_FRAME,this.yi,this);
			this.addEventListener(egret.Event.ENTER_FRAME,this.er,this);
		    var timer:egret.Timer=new egret.Timer(1000,1);
			timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE,(e:egret.TimerEvent)=>{
                this.removeEventListener(egret.Event.ENTER_FRAME,this.er,this);
				this.addEventListener(egret.Event.ENTER_FRAME,this.san,this);
		    },this);
		    timer.start();
		},this);
		timer.start();
			
	}
	private yi():void{
		this.zz.rotation+=25;
	}
	private er():void{
		this.zz.rotation+=15;
	}
	private san():void{
		this.zz.rotation+=15;
		
		    if(this.zz.hitTestPoint(330,315,true)&&this.num==6){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			    
				  if(this.num2==1){
					 this.g14.visible=true;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			if(this.zz.hitTestPoint(400,360,true)&&this.num==7){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			      
				  if(this.num2==1){
					 this.g14.visible=true;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			if(this.zz.hitTestPoint(425,435,true)&&this.num==8){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			     
				 if(this.num2==1){
					 this.g14.visible=true;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			if(this.zz.hitTestPoint(390,500,true)&&this.num==1){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			      
				  if(this.num2==1){
					 this.g14.visible=true;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			if(this.zz.hitTestPoint(310,530,true)&&this.num==2){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			       
				  if(this.num2==1){
					 this.g14.visible=true;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			
			if(this.zz.hitTestPoint(240,490,true)&&this.num==3){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			      
				  if(this.num2==1){
					 this.g14.visible=true;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			if(this.zz.hitTestPoint(210,410,true)&&this.num==4){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			    
				 if(this.num2==1){
					 this.g14.visible=false;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			if(this.zz.hitTestPoint(250,340,true)&&this.num==5){
			     this.removeEventListener(egret.Event.ENTER_FRAME,this.san,this);
			     this.zz.addEventListener(egret.TouchEvent.TOUCH_TAP,this.oncatGift,this);
			      
				 if(this.num2==1){
					 this.g14.visible=true;
					 
				 }else{
					 if(this.num1==0){
						 this.g10.visible=true;
					 }else{
						 this.g9.visible=true;
					 }
				 }
		    }
			this.onloadUserInfo();
			this.scr.scrollPolicyV="on"
			//this.leiji.text=(parseInt(this.leiji.text)+parseInt(this.huode.text))+""
			
	}
	public onloadUserInfo(): void {
        var url =  "http://ljla.wenmall.cn/zp/userInfo";


        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         
            var hehe:number=0;

			var hehe2:number=0;
		 console.log(e.target.data);
		
           var jsObj = JSON.parse(e.target.data);
		   this.guize.text=jsObj.rule
		   hehe=jsObj.total-jsObj.balance;
		   this.yitixian.text=hehe.toFixed(2)+"";;
		   hehe2=jsObj.balance;
		   this.yu.text=hehe2.toFixed(2)+"";
		   this.jine=jsObj.total;
		   this.t4.text=jsObj.time;
		   this.t3.text=jsObj.count;
		   this.t5.text=jsObj.time;
		   this.time=jsObj.time;
		   this.zuanyu.text=jsObj.time;
		   this.yiyong.text=jsObj.totalTime
		   //alert(jsObj.followed);
	
		   if(jsObj.followed==0){
			   this.followdWind();
		   }
		   if(jsObj.followed==1){
			   this.g6.visible=false;
		   }
        }, this);
        urlloader.load(req);
    }
	public oncatGift(e:egret.TouchEvent): void {
        var url =  "http://ljla.wenmall.cn/zp/catGift";

        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         

		 console.log(e.target.data);
		
           var jsObj = JSON.parse(e.target.data);
		   this.num=jsObj.gift_id
		   if(jsObj.rs==0){
                this.g5.visible=true;
		   }else{
			   this.s1()
		   }
		//alert(this.num)
		this.num2=jsObj.shiwu;
        
var count=0;

this.gifts.forEach(element => {
	

	if(element.id==this.num){
//alert;

		this.huode2.text=element.name;
		this.num1=element.count;
		this.huode3.text=element.name;
	}
	
});


//alert(count);
        }, this);
        urlloader.load(req);
    }
	private followdWind() {
		this.g6.visible = true;
		var gameDiv = document.getElementById("gameID");
		var myImg: HTMLImageElement = document.createElement("img");
		myImg.src = "http://olcchtm0c.bkt.clouddn.com/qrcode_for_gh_99149d14121d_258.jpg";

		//myImg.setAttribute("src","resource/assets/weixin.jpg");
		var imgX = 200;
		//var imgY = this.erweima.stage.y;
		var imgY = 200;
		//	var imgX = 100;
		   // left: 50%;
    //top: 200px;
    //margin-left: -100px;
		//	var imgY = 200;
		myImg.setAttribute("style", "width:200px;margin:0 auto;padding:0px;position:absolute;z-index:99999;left:50%;margin-left: -100px;top:" + imgY + "px");
		//document.body.appendChild(img);

		gameDiv.appendChild(myImg);
	}
    public jiangjin(): void {
        var url =  "http://ljla.wenmall.cn/zp/gifts";


        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         
        //this.g7.removeChildren();
		 console.log(e.target.data);
           var jsObj = JSON.parse(e.target.data);

     this.gifts=jsObj;
	//	  for(var i=0;i<10;i++){ 
   
        var gifts=1;
		jsObj.forEach(element => {
			var haha=new jiang(gifts,element)
		    haha.rotation=gifts*45;
			 
             //this.num2=element.shiwu;

			this.g7.addChild(haha);
            gifts=gifts+1;
		});
	///	}
                      
        }, this);
        urlloader.load(req);
    }
	public onlist(): void {
        var url =  "http://ljla.wenmall.cn/zp/lists";

        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         

		 console.log(e.target.data);
		
           var jsObj = JSON.parse(e.target.data);
		   var data=1;
		jsObj.data.forEach(element => {
			var a=new ming(data,element)
		    a.y=data*50-50;
		
			this.g1.addChild(a);
            data=data+1;
			
		});
        }, this);
        urlloader.load(req);
    }
	public onjilu(): void {
		
		this.g3.removeChildren()
        var url =  "http://ljla.wenmall.cn/zp/myLists";

        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         

		 console.log(e.target.data);
		
           var jsObj = JSON.parse(e.target.data);
		   var data=1;
		jsObj.data.forEach(element => {
			var a=new jilu(data,element)
		    a.y=data*50;
			this.g3.addChild(a);
            data=data+1;
			
		});
        }, this);
        urlloader.load(req);
    }
	public ontixian(): void {
        var url =  "http://ljla.wenmall.cn/zp/withdraw";

        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
		
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         alert("提交中，请稍后")

		 console.log(e.target.data);
		
           var jsObj = JSON.parse(e.target.data);
		   this.tixian2.addEventListener(egret.TouchEvent.TOUCH_TAP,this.dianji,this)
			if(jsObj){
	           if(parseInt(this.yu.text)>=1){
					 //alert(this.fail);
				
				if(jsObj.result_code=="FAIL"){
                     this.fail=jsObj.err_code_des
					 alert(this.fail);
					 //alert(jsObj)
				}else{
					this.g8.visible=true;
					this.onloadUserInfo()
				}
			   }else{
				   
				   alert("余额大于1才能提现")
			   }
			}

        }, this);
        urlloader.load(req);
    }
	public ontixian2(): void {
		this.g11.visible=true;
	
        var url =  "http://ljla.wenmall.cn/zp/withdraw";

        console.log(url);
        var urlloader = new egret.URLLoader();
        var req = new egret.URLRequest(url);
        req.method = egret.URLRequestMethod.GET;
        var self = this;
        urlloader.addEventListener(egret.Event.COMPLETE, (e) => {
         alert("提交中，请稍后")

		 console.log(e.target.data);
		
           var jsObj = JSON.parse(e.target.data);
		   this.tixian3.addEventListener(egret.TouchEvent.TOUCH_TAP,this.dianji2,this)
			if(jsObj){
	           if(parseInt(this.yu.text)>=1){
					 //alert(this.fail);
				
				if(jsObj.result_code=="FAIL"){
                     this.fail=jsObj.err_code_des
					 alert(this.fail);
					 //alert(jsObj)
				}else{
					this.g8.visible=true;
					this.onloadUserInfo()
				}
			   }else{
				   alert("余额大于1才能提现")
			   }
			}

        }, this);
        urlloader.load(req);
    }
}